package com.freesky.biz.rights.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.freesky.biz.rights.domain.RightsQuesEntity;
import com.freesky.biz.rights.domain.RightsQuesRecordEntity;
import com.freesky.biz.rights.domain.RightsThirdCardEntity;
import com.freesky.biz.rights.service.IRightsQuesService;
import com.freesky.biz.rights.service.IRightsThirdCardService;
import com.freesky.common.annotation.Log;
import com.freesky.common.core.controller.BaseController;
import com.freesky.common.core.domain.AjaxResult;
import com.freesky.common.core.page.TableDataInfo;
import com.freesky.common.enums.BusinessType;
import com.freesky.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 第三方卡券管理
 */
@RestController
@RequestMapping("/rights/thirdcard")
public class RightsThirdCardController extends BaseController {

    @Autowired
    private IRightsThirdCardService rightsThirdCardService;

    @Autowired
    private IRightsQuesService rightsQuesService;

    /**
     * 获取卡券列表
     */
    @PreAuthorize("@ss.hasPermi('rights:thirdcard:list')")
    @GetMapping("/list")
    public TableDataInfo list(RightsThirdCardEntity rightsThirdCard) {
        LambdaQueryWrapper<RightsThirdCardEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(RightsThirdCardEntity::getCreateTime);
        wrapper.eq(RightsThirdCardEntity::getDelFlag, "0");
        if(StringUtils.isNotEmpty(rightsThirdCard.getBusiName())){
            wrapper.like(RightsThirdCardEntity::getBusiName, rightsThirdCard.getBusiName());
        }
        if(StringUtils.isNotEmpty(rightsThirdCard.getBusiId())){
            wrapper.like(RightsThirdCardEntity::getBusiId, rightsThirdCard.getBusiId());
        }
        if(StringUtils.isNotEmpty(rightsThirdCard.getName())){
            wrapper.like(RightsThirdCardEntity::getName, rightsThirdCard.getName());
        }
        if(StringUtils.isNotEmpty(rightsThirdCard.getCardNo())){
            wrapper.like(RightsThirdCardEntity::getCardNo, rightsThirdCard.getCardNo());
        }

        if(StringUtils.isNotEmpty(rightsThirdCard.getStockId())){
            wrapper.like(RightsThirdCardEntity::getStockId, rightsThirdCard.getStockId());
        }
        if(StringUtils.isNotEmpty(rightsThirdCard.getReceiveId())){
            wrapper.eq(RightsThirdCardEntity::getReceiveId, rightsThirdCard.getReceiveId());
        }
        IPage<RightsThirdCardEntity> list = rightsThirdCardService.page(plusPage(), wrapper);
        return getDataTable(list);
    }
}
